package container.map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class TestHashMap
{
    public static void main (String[] args)
    {
        Map<Integer, String> HashMap1 = new HashMap<>();
        Map<Integer, String> HashMap2 = new HashMap<>();
        
        String hash1 = HashMap1.put(1, "A");
        String hash2 = HashMap1.put(2, "c");
        String hash3 = HashMap1.put(1, "chen");
        String hash4 = HashMap1.put(3, "oldlu");
        String hash5 = HashMap2.put(5, "666");
        String hash6 = HashMap2.put(8, "ilu");
        
        int size = HashMap1.size();
        System.out.println(size);
        System.out.println("---------------------------");
        
        String value = HashMap1.get(1);
        System.out.println(value);
        System.out.println("---------------------------");
    
        for(Integer key : HashMap1.keySet())
        {
            System.out.println(key + "-------" + HashMap1.get(key));
        }
        System.out.println("---------------------------");
        
        //Map.Entry，一个Entry就是一个键值对
        Set<Map.Entry<Integer, String>> entrySet = HashMap1.entrySet();
        for(Map.Entry<Integer, String> temp : entrySet)
        {
            Integer tempKey = temp.getKey();
            String tempValue = temp.getValue();
            System.out.println(tempKey + "-------" + tempValue);
        }
        System.out.println("---------------------------");
        
        HashMap1.putAll(HashMap2);
    
        for(Integer key : HashMap1.keySet())
        {
            System.out.println(key + "-------" + HashMap1.get(key));
        }
        System.out.println("---------------------------");
        
        boolean bool1 = HashMap1.containsKey(8);
        System.out.println(bool1);
        boolean bool2 = HashMap2.containsValue("chen");
        System.out.println(bool2);
    }
}
